package li.controller;

import li.dto.Credit;
import li.dto.Payback;
import li.dto.TbAmount;
import li.dto.TbUser;
import li.service.CreditService;
import li.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class CreditCtrl {
    @Autowired
    CreditService cs;

    @Autowired
    PayService ps;

    @RequestMapping("/selectAmount")
    public TbAmount findUserAmount(HttpSession session){
        TbUser user = (TbUser) session.getAttribute("user");
        return cs.findUserAmount(user);
    }

    @RequestMapping("/aplly")
    public TbAmount updateUserAmount(HttpSession session){
        TbUser user = (TbUser) session.getAttribute("user");
        return cs.updateUserAmount(user);
    }

    @RequestMapping("/credits")
    public List<Credit> findUserCredits(HttpSession session){
        TbUser user = (TbUser) session.getAttribute("user");
        return cs.findUserCredits(user);
    }


    @RequestMapping("/payback")
    public List<Payback> findUserPayback(HttpSession session){
        TbUser user = (TbUser) session.getAttribute("user");
        return ps.findUser7Pay(user);
    }
}

